package com.yao.home;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.Getter;

import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 通用状态枚举
 * @author yaoyuming
 * @date 2020/03/26 15:38
 */
@Getter
public enum CommonStatusEnum {
    VALID(0, "有效"),
    INVALID(1, "无效");

    @EnumValue
    private final int code;

    @JSONField
    private final String desc;

    CommonStatusEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    private static Map<Integer, String> enums = Stream.of(CommonStatusEnum.values()).collect(Collectors.toMap(CommonStatusEnum::getCode, CommonStatusEnum::getDesc));

    public static String getDesc(int code){
        return enums.get(code);
    }
}
